package my.edu.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Slf4j
public class ToolAspect {

    @Pointcut("execution(* my.edu.model..*.controller.*.*(..)) ")
    //第一个*：返回值类型；后面就是 my.edu.model 包及其所有子包中的 controller 子包下的所有方法，包括所有参数类型
    public void autoFillPointCut() {
    }

    @Pointcut("@annotation(my.edu.aspect.LogExecutionTime)")
    public void logExecutionTimePointCut() {
    }

    @Around("autoFillPointCut() && logExecutionTimePointCut()")
    public Object logMethod(ProceedingJoinPoint joinPoint) throws Throwable {
        long s = System.currentTimeMillis();
        Object result = result = joinPoint.proceed();
        long e = System.currentTimeMillis();
        System.out.println("-*//*-/*-/*-/*--/*/-*耗时：" + (e - s));
        return result;
    }
}